﻿using UnityEngine;
using System.Collections;
using Assets.Scripts.Common;
using XLua;

partial class LuaService : MonoSingleton<LuaService>
{
    private LuaEnv mLuaEnv;
    public LuaEnv LuaEnv
    {
        get { return mLuaEnv; }
        set { mLuaEnv = value; }
    }

    private LuaFunction mFireEvent;

    public override void Init()
    {
        base.Init();

        if (mLuaEnv != null)
        {
            return;
        }

        mLuaEnv = new LuaEnv();
    }

    public void StartLua()
    {
        LuaEnv.Global.Set("InUnity", true);
        LuaEnv.DoFile("Data/Scripts/Booter/Main.lua");

        mFireEvent = mLuaEnv.Global.Get<LuaFunction>("FireEvent");
        FireEvent("OnPPP",11);
    }

    public LuaTable NewTable()
    {
        if (null == mLuaEnv)
        {
            return null;
        }
        return mLuaEnv.NewTable();
    }

    protected override void OnDestroy()
    {
        if (mLuaEnv != null)
        {
            mLuaEnv.Dispose();
        }
    }
}
